package cn.tedu.charging.cost.repository;

import cn.tedu.charging.common.pojo.po.ChargingCostRulePO;
import cn.tedu.charging.cost.mapper.ChargingCostRuleMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class CostRepository {
    @Autowired
    private ChargingCostRuleMapper chargingCostRuleMapper;

    public ChargingCostRulePO getCostRule(Integer stationId, Date now) {
        //where station_id=? and start_time<=now.getHour() and now.getHour()<end_time
        //1.通过Date now 获取当前系统时间的小时数数字
        //<= lte|le(less than and equal) >= gte|ge(greater than and equal)
        //<lt >gt
        int hour = now.getHours();
        QueryWrapper<ChargingCostRulePO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("station_id",stationId)
                .le("start_time",hour).gt("end_time",hour);
        return chargingCostRuleMapper.selectOne(queryWrapper);
    }
}
